<?
    /* -*- Mode: PHP5; tab-width: 4; indent-tabs-mode: nil; basic-offset: 4 -*- */
    
    /*********************************************************
    *            --== InArch ==--
    *
    * This is the key class to all the admin side data nodes.
    * It is extended into child classes which do all the work.
    *
    * @author Kulikov Alexey <a.kulikov@gmail.com>
    * @version n/a
    * @since 25.05.2005
    * @copyright essentialmind.com 2005
    *
    *********************************************************/
    
    /***
    * Class adminNodeEstae
    ****
    * This class handles estate folders
    ****
    * @package adminNodes
    * @author Thomas Brandstaetter <tb@essentialmind.com>
    * @version n/a
    * @since 09.05.2011
    * @copyright essentialmind.com 2011
    ***/
    class adminNodeEstateReferenceFolder extends adminNode{
        
        /**
         * @brief hold the datatype id of the estate node
         */
        private $estateType;
        
        /**
         * Processes all the user inputs!
         *
         */
        function process(){
            if($_POST)
				$this->update();
            else
            	$this->show();
        }
        
        protected function show() {
        
        	$node = $this->db->getRow("SELECT 
                                           objectmap.title, 
                                           content 
                                       FROM objectmap
                                       LEFT JOIN node_estate_reference_folder nerf ON objectmap.objectid = nerf.id 
                                       WHERE version = 1 AND objectmap.nodeid = " . $this->noderef);
                                       
        	$this->smarty->assign('node', $node);
        }
        
        protected function update() {
			
			//update database record
        	$this->db->Execute("UPDATE node_estate_reference_folder SET content = '".addslashes($_POST['content'])."' WHERE id = " . $this->object);
            
            //updates the status of the page (title, wf state)
            $this->updateNodeStatus();
            
            //make a note of the ajax request
            $this->log->recordAction("Updated Estate Reference Folder (".$this->object.") with global id (".$this->noderef.")");
            
            header('Location: '.$this->request.'&confirm=true');
            exit;
        }
        
        
        /**
         * Sets the main template for the action
         *
         */
        function setTemplate(){
            $this->setActionTemplate('nodes/editEstateReferenceFolder.html');
        }
        
        /**
         * Sets the ID of an estatetype to this instance.
         * @detail Globals: this->estateType.
         *
         * @param void
         * @return void
         */
        private function setEstateType() {
            $this->estateType = (int)$this->db->getOne("SELECT id FROM datatype WHERE codeset = 'estate'");
            if($this->estateType == 0){
                throw new Exception("No estate datatype registered with the system!");   
            }
        }
        
        
        /**
         * Adds an instance to the data tree
         *
         * @return unknown
         */
        function addInstance(){          
            $this->db->Execute("INSERT INTO node_estate_reference_folder(content) VALUES('')");
            return $this->db->getOne("SELECT last_value FROM node_estate_reference_folder_id_seq");
        }
    }
?>